import * as cc from "cc";
import yyComponent from "../../Script/Common/yyComponent";
import { GlobalEnum } from "../../Script/GameSpecial/GlobalEnum";
import { EventType } from "../../Script/GameSpecial/GameEventType";
import GlobalData from "../../Script/Common/GlobalData";

const { ccclass, property } = cc._decorator;

@ccclass
export default class LoseUI extends yyComponent {

    /**场景/UI类型 */
    public get uiType() { return GlobalEnum.UI.loseUI; }

    protected setData(data) {
        this.gold = data.gold;
        this.goldLabel.string = data.gold.toString();
        this.mingCi.string = data.mingCi + "";

    }


    public show(data?) {
        this.reset();
        this.node.active = true;
        if (undefined !== data) {
            this.setData(data);
        }
        this.emit(EventType.Common.UIEvent.enter, GlobalEnum.UI.playerAssetBar);
    }

    @property(cc.Label)
    protected mingCi: cc.Label = null;

    @property(cc.Label)
    protected goldLabel: cc.Label = null;
    protected gold: number = 0;

    //视频多倍领取
    protected onBtnVideo() {
        this.playClickBtn();
        this.emit(EventType.Common.SDKEvent.showVideo, {
            success: () => {
                this.addGold(this.gold * 3, this.enterLobby.bind(this));
            },
        });
    }

    protected onContinueGame() {
        this.emit(EventType.Common.AudioEvent.playClickBtn);
        this.addGold(this.gold, this.enterLobby.bind(this));
        // this.enterLobby();
    }

    protected enterLobby() {
        this.emit(EventType.Common.DirectorEvent.enterLobby);
    }

    /**播放金币动画获得金币 */
    protected addGold(gold: number, cb?: Function) {
        this.emit(EventType.Common.UIEvent.playGoldAnim, {
            cb: () => {
                this.emit(EventType.Common.PlayerDataEvent.updatePlayerData, {
                    attribute: "gameData.asset.gold",
                    value: gold,
                    mode: "+",
                    emit: true,
                    save: true,
                });
                !!cb && cb();
            },
            gold: gold,
        })
    }

    protected onBtnMoreGame() {
        this.emit(EventType.Common.SDKEvent.showAppBox);
    }

    protected onBtnShare() {
        this.emit(EventType.Common.SDKEvent.shareToFriends);
    }
}
